// pages/underLine/underLine.js
const app = getApp();
var router = require("../../router.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    summer: [],
    free_summer: [],
    src_1: "../../image/btna2.jpg",
    src_2: "../../image/btnb1.jpg",
    isChose: true,
    imgUrls: [ //banner图片数据    
    ],
    indicatorDots: true, //是否添加轮播小圆点
    autoplay: true, //是否自动播放
    interval: 5000, //轮播间隔时间
    duration: 1000 //动画过渡时间
  },
  // 底部
  index: function() {
    app.radTo('../index/index')
  },
  underLine: function() {
    app.radTo('../underLine/underLine')
  },
  course: function() {
    app.radTo('../course/course')
  },
  distribution: function() {
    app.radTo('../distribution/distribution')
  },
  mine: function() {
    app.radTo('../mine/mine')
  },
  personal: function(e) {
    if (this.data.isChose == false) {
      this.data.isChose = !this.data.isChose
      this.setData({
        isChose: this.data.isChose,
      })
      this.setData({
        src_1: "../../image/btna2.jpg",
        src_2: "../../image/btnb1.jpg"
      })
    }
  },
  company: function(e) {
    if (this.data.isChose == true) {
      this.data.isChose = !this.data.isChose
      this.setData({
        isChose: this.data.isChose,
      })
      this.setData({
        src_1: "../../image/btna1.jpg",
        src_2: "../../image/btnb2.jpg",
        isChose: false
      })
    }
  },
  to_detail(e) {
    let id = e.currentTarget.dataset.index;
 
   
    app.navTo('../active_detail/active_detail?id=' + id)
  },

  open_this_line(e) {
    let index = e.currentTarget.dataset.index;
    var free_summer = this.data.free_summer;
    free_summer[index].show_child = !free_summer[index].show_child
    this.setData({
      free_summer: free_summer
    })
  },

  open_this_line2(e) {
    let index = e.currentTarget.dataset.index;
    var summer = this.data.summer;

    summer[index].show_child = !summer[index].show_child
    this.setData({
      summer: summer
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    app.request({
      url: router.course.index,
      method: "POST",
      success: function(data) {
        for (let i = 0; i < data.free_course.length; i++) {
          data.free_course[i].show_child = false;
        }
        for (let i = 0; i < data.charge_course.length; i++) {
          data.charge_course[i].show_child = false;
        }
        console.log(data.charge_course[0])
        that.setData({
          imgUrls: data.banner,
          summer: data.charge_course,
          free_summer: data.free_course,
        });
      }
    })
  },
})